package com.example.toutiao.ui.activity;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.toutiao.R;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

//文章详情
public class ArticleDetailActivity extends AppCompatActivity {

    private TextView tvTitle, tvAuthor, tvTime, tvContent;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_article_detail);
        TextView tabBarTitle = findViewById(R.id.tabBarTitle);
        tabBarTitle.setText("文章详情");

        // 获取文章详情视图
        tvTitle = findViewById(R.id.tvTitle);
        tvAuthor = findViewById(R.id.tvAuthor);
        tvTime = findViewById(R.id.tvTime);
        tvContent = findViewById(R.id.tvContent);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        String formattedTime;

        String title = getIntent().getStringExtra("title");
        String author = getIntent().getStringExtra("author");
        String time = getIntent().getStringExtra("time");
        try {
            long timestamp = Long.parseLong(time);
            formattedTime = sdf.format(new Date(timestamp));
        } catch (NumberFormatException e) {
            formattedTime = "未知时间";
        }
        String content = getIntent().getStringExtra("content");

        // 设置文本内容
        tvTitle.setText("标题："+title);
        tvAuthor.setText("作者："+author);
        tvTime.setText("发布时间：："+formattedTime);
        tvContent.setText(content);
    }
}
